home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
utils
/
tlayr10
/
tilemain.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-19
|
8KB
|
263 lines
// TILE LAYER v1.0
// Main module
// -------------------------------------------------
#include <stdio.h>
#include <string.h>
// -------------------------------------------------
#include "mouse.h"
#include "graph13h.h"
#include "layrglob.h"
#include "basicobj.h"
#include "laystuff.h"
// -------------------------------------------------
extern "C" void put_arrow(unsigned, unsigned);
extern "C" void xor_rect(unsigned, unsigned, unsigned, unsigned, unsigned );
extern char layrfont[1024];
void Drawcursor();
// -------------------------------------------------
// This class contain al the hot_areas of the application
// and react only to the CMD_QUIT command generated by the menu buttons.
// For further information about Class hot_area see file BASICOBJ.H
class application: public command_target {
hot_area_group *application_areas;
unsigned finished;
public:
application(hot_area **);
virtual ~application();
virtual void run();
virtual int handle_command(unsigned );
};
// -------------------------------------------------
application::application(hot_area **active_areas)
{
static char logo[]= "\r Tile Layer v1.0\r"
"programmed by: gaggi@cs.unibo.it\r"
"\r Press any key to continue\r";
set_video( MODE_13H );
CurFont= (char far *)layrfont;
set_palette( def_palette );
if ( resetmouse() )
{
message_Window *heila= new message_Window(0,0, WNDW_DEF | WNDW_CNT,logo);
heila->show_mes();
delete heila;
finished= 0;
application_areas= new hot_area_group(active_areas);
application_areas->draw();
Install_mouse();
SetDrawProc( Drawcursor );
mouse_cursor( ON );
}
else {
Error(MOUSE_ERR);
application_areas= NULL;
finished= 1;
};
}
application::~application()
{
if ( application_areas ) delete application_areas;
resetmouse();
set_video( TEXT_MODE );
puts("Thank you for using my software, hope you enjoyed it!\n"
"Feel free to send any comment or feedback to: gaggi@cs.unibo.it");
}
void application::run()
{
while(!finished) application_areas->is_mouse_up();
}
int application::handle_command(unsigned command)
{
if (command == CMD_QUIT)
{
return finished++;
};
return -1;
}
// -------------------------------------------------
unsigned _stklen = 2*1024;
unsigned _heaplen= 5*1024;
extern application My_appl;
tile_set *tiles = new tile_set(MAX_WORLD_X + 2, 2);
world_editor *editor= new world_editor(tiles, DEFAULT_BUF_LLENGTH,
DEFAULT_BUF_LINES);
hot_area *application_obj[]= {
editor,
tiles,
// Menu Buttons
new button(MAX_WORLD_X + 2, 122, "Load TIL", CMD_LOAD_SET , editor),
new button(MAX_WORLD_X + 2, 135, "Load WLD", CMD_LOAD_WORLD , editor),
new button(MAX_WORLD_X + 2, 148, "Save WLD", CMD_SAVE_WORLD , editor),
new button(MAX_WORLD_X + 2, 161, "WLD Info", CMD_SHOW_INFO , editor),
new button(MAX_WORLD_X + 2, 174, "Redim ", CMD_REDIM_WORLD, editor),
new button(MAX_WORLD_X + 2, 187, "Quit ", CMD_QUIT , &My_appl),
// Scroll of tile set and edit window
new pan_control(MAX_WORLD_X + 2, 40, tiles, LEFT_PAN ),
new pan_control(MAX_WORLD_X + 15, 40, tiles, RIGHT_PAN),
new pan_control(MAX_WORLD_X + 25, 70, editor, UP_PAN),
new pan_control(MAX_WORLD_X + 25, 96, editor, DOWN_PAN),
new pan_control(MAX_WORLD_X + 12, 83, editor, LEFT_PAN),
new pan_control(MAX_WORLD_X + 38, 83, editor, RIGHT_PAN),
(hot_area *)0
};
application My_appl(application_obj); // Builds the applications object !
// -------------------------------------------------
void Drawcursor()
// Mouse cursor drawing function
// Very complex to explain! (especially for me :) )
{
static unsigned char first_time= 1, rect_on= 0;
static unsigned char cursor_area[68];
register unsigned MouseX= Mouse.PointX >> 1,
MouseY= Mouse.PointY;
asm push bx
asm push cx
asm push dx
if (first_time)
{
if ( MouseX >= editor->xsize || MouseY >= editor->ysize )
{ // The cursor is out of the area
// covered by the edit window
if ( rect_on ) // If there was the rectangle near
{ // the cursor ...
rect_on--; // ... delete it
xor_rect(editor->cur_x, editor->cur_y, tiles->tile_x,
tiles->tile_y, 0x0F);
editor->cur_x= editor->cur_y= 65535; // Force the drawing
// of the rectangle when
// the cursor will be within
// the edit window
};
}
else { // The cursor is within the area covered by the edit window
unsigned temp_cur_x= MouseX - (MouseX % tiles->tile_x);
unsigned temp_cur_y= MouseY - (MouseY % tiles->tile_y);
// Adjourn if necessary the rectangle's position
if ( !rect_on || temp_cur_x != editor->cur_x ||
temp_cur_y != editor->cur_y )
{
// Delete the previous one if present
if ( rect_on )
xor_rect(editor->cur_x, editor->cur_y, tiles->tile_x,
tiles->tile_y, 0x0F);
else rect_on++;
// Adjourn its coordinates and draw the new one
xor_rect(editor->cur_x= temp_cur_x, editor->cur_y= temp_cur_y,
tiles->tile_x, tiles->tile_y, 0x0F);
}
};
// Mouse cursor drawing
save_area(MouseX, MouseY, 8, 8, (char far *)cursor_area);
put_arrow(MouseX, MouseY);
first_time--;
}
else {
put_area(MouseX, MouseY, (char far *)cursor_area);
if ( !Mouse.Cursor && rect_on )
{
rect_on--;
xor_rect(editor->cur_x, editor->cur_y, tiles->tile_x,
tiles->tile_y, 0x0F);
};
first_time++;
};
asm pop dx
asm pop cx
asm pop bx
}
// -------------------------------------------------
static char *error_messages[]= {
"\rMemory allocation fault\r",
"Unable to open file \r%s\r",
"\rMouse not found ... aborting\r"
"\r Hit a key to continue\r"
};
void Error(unsigned err_msg, void *info)
{
message_Window *err_wnd;
char buffer[80];
if ( info )
{
sprintf(buffer, error_messages[err_msg], info);
if ( strlen(buffer) > 55 )
{
buffer[55]= '\r';
buffer[56]= 0;
};
err_wnd= new message_Window(10, 10, WNDW_DEF | WNDW_CNT, buffer);
}
else err_wnd= new message_Window(10, 10, WNDW_DEF | WNDW_CNT,
error_messages[err_msg]);
err_wnd->show_mes();
delete err_wnd;
}
// -------------------------------------------------
main() // Here is all the main !!!!
{ // Wow, this is the power of object-oriented programming!
My_appl.run();
}
// ---------------- End of file ----------------